package com.yunwushanhe.controller;



import com.yunwushanhe.annotation.SystemLog;
import com.yunwushanhe.bean.req.ArticleAddReq;
import com.yunwushanhe.bean.req.ArticlePageReq;
import com.yunwushanhe.bean.req.ArticleUpdateReq;
import com.yunwushanhe.bean.ret.ResponseResult;
import com.yunwushanhe.bean.vo.ArticleAdminPageVO;
import com.yunwushanhe.bean.vo.ArticleUpdateVO;
import com.yunwushanhe.bean.vo.PageVO;
import com.yunwushanhe.entity.Article;
import com.yunwushanhe.entity.Menu;
import com.yunwushanhe.service.ArticleService;
import com.yunwushanhe.service.MenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文章表(Article)表控制层
 *
 * @author 抬头看看天
 * @since 2023-08-22 22:29:37
 */
@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Resource
    private ArticleService articleService;
    @Resource
    private MenuService menuService;

    @PostMapping
    @SystemLog(businessName = "增加文章的接口")
    public ResponseResult<Object> addArticle(@RequestBody ArticleAddReq articleAddReq){
        return articleService.addArticle(articleAddReq);
    }

    @GetMapping("/list")
    public ResponseResult<PageVO<List<ArticleAdminPageVO>>> listAllArticle(ArticlePageReq articlePageReq){
        return articleService.listAllArticle(articlePageReq);
    }

    @GetMapping("/{id}")
    public ResponseResult<ArticleUpdateVO> getArticleById(@PathVariable("id") Long id){
        return articleService.getArticleById(id);
    }

    @PutMapping
    public ResponseResult<Object> updateArticleById(@RequestBody ArticleUpdateReq articleUpdateReq){
        return articleService.updateArticleById(articleUpdateReq);
    }

    @DeleteMapping("/{id}")
    public ResponseResult<Object> deleteArticleById(@PathVariable("id") String id){ // 由于前端页面有两种删除的请求方式，这里改为String接收可以应对多种情况
        return articleService.deleteArticleById(id);
    }
    /*
     Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long';
     nested exception is java.lang.NumberFormatException: For input string: "8,7"
     这个异常的抛出很有很有可能是请求方式不对应或是请求参数不对应造成的
    */
}

